//
//  YZLSubBrandListCell.m
//  Car
//
//  Created by dllo on 15/11/7.
//  Copyright © 2015年 岳明. All rights reserved.
//

#import "YZLSubBrandListCell.h"
#import "Macro.h"
#import "YZLSeriesListModel.h"

@interface YZLSubBrandListCell ()

@property (nonatomic, strong) UILabel *leftLabel;
@property (nonatomic, strong) UILabel *middleLabel;
@property (nonatomic, strong) UILabel *rightLabel;

@end

@implementation YZLSubBrandListCell

- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier {
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if (self) {
        self.leftLabel = [[UILabel alloc] init];
        [self.contentView addSubview:self.leftLabel];
        
        self.middleLabel = [[UILabel alloc] init];
        [self.contentView addSubview:self.middleLabel];
        
        self.rightLabel = [[UILabel alloc] init];
        self.rightLabel.textColor = [UIColor orangeColor];
        [self.contentView addSubview:self.rightLabel];
    }
    return self;
}

- (void)layoutSubviews {
    [super layoutSubviews];
    self.leftLabel.frame = CGRectMake(15, 0, kWidth / 3, self.contentView.frame.size.height);
    self.middleLabel.frame = CGRectMake(kWidth / 3, 0, 70, self.contentView.frame.size.height);
    self.rightLabel.frame = CGRectMake(self.middleLabel.frame.origin.x + self.middleLabel.frame.size.width, 0, kWidth - self.middleLabel.frame.origin.x + self.middleLabel.frame.size.width, self.contentView.frame.size.height);
}

- (void)setSearchString:(NSString *)searchString {
    if (_searchString != searchString) {
        _searchString = searchString;
    }
    NSString *str = [[_model.seriesName stringByReplacingOccurrencesOfString:@"<font color=\"red\">" withString:@""] stringByReplacingOccurrencesOfString:@"</font>" withString:@""];
    NSMutableAttributedString *leftAtt = [[NSMutableAttributedString alloc] initWithString:str];
    NSRange range = [str rangeOfString:searchString];
    [leftAtt setAttributes:@{NSForegroundColorAttributeName:[UIColor redColor],NSFontAttributeName:[UIFont systemFontOfSize:17]} range:range];
    _leftLabel.attributedText = leftAtt;
}

- (void)setModel:(YZLSeriesListModel *)model {
    if (_model != model) {
        _model = model;
    }
    _middleLabel.text = @"指导价：";
    _rightLabel.text = model.guidePrice;
}

- (void)awakeFromNib {
    // Initialization code
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}

@end
